package com.ruoyi.server.api.imgsorting.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.imgsorting.domain.ImageSorting;
import com.ruoyi.server.api.imgsorting.service.IImageSortingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上传轮播图Controller
 * 
 * @author ruoyi
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/imgsorting/imgsorting")
public class ImageSortingController extends BaseController
{
    @Autowired
    private IImageSortingService imageSortingService;

    /**
     * 查询上传轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageSorting imageSorting)
    {
        startPage();
        List<ImageSorting> list = imageSortingService.selectImageSortingList(imageSorting);
        return getDataTable(list);
    }

    /**
    * @Author zsc
    * @Description 查询轮播图列表
    * @Date 2024/11/29 14:55
    * @Return com.ruoyi.common.core.domain.AjaxResult
    * @param imageSorting
    */
    @GetMapping("/lists")
    public AjaxResult lists(ImageSorting imageSorting)
    {
        List<ImageSorting> list = imageSortingService.selectImageSortingList(imageSorting);
        return success(list);
    }

    /**
     * 导出上传轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:export')")
    @Log(title = "上传轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImageSorting imageSorting)
    {
        List<ImageSorting> list = imageSortingService.selectImageSortingList(imageSorting);
        ExcelUtil<ImageSorting> util = new ExcelUtil<ImageSorting>(ImageSorting.class);
        util.exportExcel(response, list, "上传轮播图数据");
    }

    /**
     * 获取上传轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imageSortingService.selectImageSortingById(id));
    }

    /**
     * 新增上传轮播图
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:add')")
    @Log(title = "上传轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImageSorting imageSorting)
    {
        return toAjax(imageSortingService.insertImageSorting(imageSorting));
    }

    /**
     * 修改上传轮播图
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:edit')")
    @Log(title = "上传轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageSorting imageSorting)
    {
        return toAjax(imageSortingService.updateImageSorting(imageSorting));
    }

    /**
     * 删除上传轮播图
     */
    @PreAuthorize("@ss.hasPermi('imgsorting:imgsorting:remove')")
    @Log(title = "上传轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imageSortingService.deleteImageSortingByIds(ids));
    }
}
